package com.wuxiaofan.common.exception;

import com.wuxiaofan.common.vo.ReturnResult;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class CustomExceptionHandle {

    @ExceptionHandler(Exception.class)
    public ReturnResult ExceptionHandler(Exception e) {
        if (e instanceof BindException) {
            return ReturnResult.failure(((BindException) e).getBindingResult().getAllErrors().get(0).getDefaultMessage());
        }
        return ReturnResult.failure(e.getMessage());
    }


}
